package com.credit.task;

import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.credit.entity.CreditLoanOrder;
import com.credit.service.CreditOrderService;
import com.credit.util.CodeValueUtil;



public class UpdateCreditOrderStatusTask {
	private static final Log log = LogFactory.getLog(UpdateCreditOrderStatusTask.class);
	@Autowired
	private CreditOrderService creditOrderService;
      
    public void updateStatus() throws IOException {
    	
    	log.info("定时修改订单状态......");
    	
    	updateExclusiveOrder();
    	
    	updateOrdinaryOrder();
    	
    }


	private void updateOrdinaryOrder() { //普通单
		Date nowDate = new Date();
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(nowDate);
		calendar.add(Calendar.DAY_OF_MONTH, -3);
		
		List<CreditLoanOrder> list = creditOrderService.findOrderListByFlushTime(CodeValueUtil.ORDERTYPE_ORDINARY,calendar.getTime());
		
		creditOrderService.batchUpdate(list);
		
	}

	
	
	

	private void updateExclusiveOrder() {//专属单
		
		Date nowDate = new Date();
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(nowDate);
		calendar.add(Calendar.DAY_OF_MONTH, -1);
		
		List<CreditLoanOrder> list = creditOrderService.findOrderListByFlushTime(CodeValueUtil.ORDERTYPE_EXCLUSIVE,calendar.getTime());
		
		creditOrderService.batchUpdate(list);
		
	}

}
